package com.voxel.sense.infomsg.module.firm.details.device;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.example.com.common.app.PresenterFragment;
import com.voxel.sense.infomsg.R;
import com.voxel.sense.infomsg.view.decoration.LinearItemDecoration;

import java.util.List;

import butterknife.BindView;
import cyy.example.com.facotry.constants.IntentConstants;
import cyy.example.com.facotry.model.api.response.FirmDeviceInfoBean;

public class FirmDeviceFrag extends PresenterFragment<FirmDeviceContaract.Presenter>
  implements FirmDeviceContaract.View<List<FirmDeviceInfoBean>> {

  @BindView(R.id.recycle_view)
  RecyclerView recyclerView;
  @BindView(R.id.not_data)
  TextView mNotData;
  private FirmDevicesAdapter firmDevicesAdapter;
  private String mCompanyid;

  @Override
  protected FirmDeviceContaract.Presenter initPresenter() {
    return new FirmDevicePresenter(this);
  }

  @Override
  protected void initData() {
    mPresenter.start();
    mPresenter.getDevicesList(mCompanyid);
    initAdapter();
  }


  @Override
  protected void initArgs(Bundle bundle) {
    super.initArgs(bundle);

    mCompanyid = bundle.getString(IntentConstants.STRING_TYPE);
  }

  private void initAdapter() {
    firmDevicesAdapter = new FirmDevicesAdapter(null);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    //设置下划线
    LinearItemDecoration linearItemDecoration = new LinearItemDecoration(R.drawable.recycle_divider_10dp);
    linearItemDecoration.setDrawFirstItem(true).
      setDrawVerticalModelLeftAndRightBorder(true,true);
    recyclerView.addItemDecoration(linearItemDecoration);
    recyclerView.setAdapter(firmDevicesAdapter);
  }

  @Override
  protected int getContentLayoutId() {
    return R.layout.frag_device_list;
  }

  @Override
  public void onRefreshData(List<FirmDeviceInfoBean> data) {
    getActivity().runOnUiThread(new Runnable() {
      @Override
      public void run() {
        if(data != null && data.size() > 0) {
          firmDevicesAdapter.replace(data);
          mNotData.setVisibility(View.GONE);
        }else{
          mNotData.setVisibility(View.VISIBLE);
        }
      }
    });

  }

  @Override
  public void onShowDownPogress() {

  }

  @Override
  public void onDismissDownProgress() {

  }
}
